/*
 * @Author: Anan 
 * @Date: 2022-05-09 22:49:52 
 * @Last Modified by: Anan
 * @Last Modified time: 2022-05-11 21:49:01
 */



import { Effect, Reducer } from 'umi';
import { getMenuList, getProdTag } from '@/services'
import { MenuObject } from '@/types'

export interface MenuModelState {
  menuList: MenuObject[];
}

export interface MenuModelType {
  namespace: 'sys-menu';
  state: MenuModelState;
  effects: {
    getMenuList:Effect;
  };
  reducers: {
    save: Reducer<MenuModelState>;
  };
}

const MenuModel: MenuModelType = {
  namespace: 'sys-menu',
  state: {
    menuList: [],
  },

  effects: {
    *getMenuList({payload}, {call, put}){
      console.log('aaaa')
      let result = yield call(getMenuList);
      localStorage.setItem('menuList',JSON.stringify(result));
      console.log(result[100],'menu...');
      if (result){
        console.log('llllll')
        yield put({
          type: 'save',
          payload: {
            menuList: result
          }
        })
      }
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};

export default MenuModel;